<?php
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); 
//ini_set('display_errors', '1');
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Main extends a_base {

    public function __construct() {
        parent::__construct();
        
        $this->checkLoginStatus();
        
    }

    private function checkLoginStatus() {
        if (!$this->session->userdata['user_id'] || empty($this->session->userdata['user_id'])) {
           redirect('login');
        }
    }

    public function index() {
        $roleIdArr = $this->m_public->getRowInfo('admin',array('adminid'=>$this->session->userdata['user_id']),'sysroleids');
        if(!empty($roleIdArr)){
            $ids = explode(',',$roleIdArr['sysroleids']);
            foreach ($ids as $key => $value) {
                if($value == '-1' || !$value){ continue;}
                $groupname = $this->m_public->getRowInfo('sysrole',array('sysroleid'=>$value));
            }
        }
        $data['groupname'] = $groupname;
        /*echo '<meta charset="utf-8">';
        var_dump($groupname);*/
        $this->load->helper('array_func_helper');
        $where['column'] = 'sysmoduleid,modulename,modulevalue,moduleurl,parentid,listid';
        $where['from'] = 'sysmodule';
        $where['order'] =  'listid asc';
        $where['where'] = array('isclose'=>0);
        $moduleArr = $this->m_public->get_list($where);

        //根据当前用户的角色获取相应的权限
        $moduleids = explode(',', $groupname['sysmoduleids']);
        $newmoduleArr = array();
        /*echo '<meta charset="utf-8">';
        var_dump($moduleids);exit;*/
        foreach($moduleArr as $k=>$v){
            if(in_array($v['sysmoduleid'], $moduleids)){
                $newmoduleArr[] = $v;
            }
        }
        $data['info'] = _findChildren($newmoduleArr,0);
        unset($moduleArr);unset($newmoduleArr);
        $this->load->view('main/index',$data);
    }
    
    function welcome(){
         $this->load->view('main/welcome');
    }

    public function resetpassword(){
        $info = $this->input->post();
        if(!empty($info)){
            $adminid = $this->session->userdata['user_id'];
            if(!$adminid){
                redirect('login');
            }
            $userinfo = $this->m_public->getRowInfo('admin',array('adminid'=>$adminid));
            if(md5($info['adminpass']) != $userinfo['adminpass']){
                $data['message'] = '旧密码不正确';
            }else{
                $this->m_public->editInfo(array('adminid'=>$adminid),array('adminpass'=>md5($info['newadminpass'])),'admin');
                $url = site_url('login/logout');
                echo "<script>parent.window.location.href='".$url."';</script>";
            }
        }
        $this->load->view('main/resetpassword',$data);
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */